<?php
/**
 * Created by PhpStorm.
 * User: dy
 * Date: 2019/12/20
 * Time: 15:13
 */
namespace app\admin\model;
use app\admin\enum\AdminMenuEnum;
use app\common\model\BaseModel;
use think\Request;

class AdminMenu extends BaseModel
{
    public function getIsHideTextAttr($value,$data){
        return AdminMenuEnum::is_hide[$data['is_hide']];
    }
    public function ParentMenu(){
        return $this->belongsTo('AdminMenu','parent_id');
    }

    public function buildParams(Request $request){
        $where = [];
        $page = $request->get('page');
        $limit = $request->get('limit');
        $order = $request->get('order','ASC');
        $sort = $request->get('sort','sort');
        $data = $request->get();
        if(!empty($data['search_data'])){
            $where[] = ['name|url','like',"%{$data['search_data']}%"];
        }
        return [$where,$sort,$order,$page,$limit];
    }
}